package routers

import (
	"github.com/gin-gonic/gin"
	"xm_shop/controllers/api"
	"xm_shop/controllers/tool"
	. "xm_shop/middleware"
)

func InitDefaultRouter(r *gin.Engine) {
	defaultRouters := r.Group("/default") // 创建子路由对象
	{
		// 商城首页信息
		defaultRouters.GET("/index", api.DefaultController{}.Index)
		// 商品分类对应商品数据
		defaultRouters.GET("/category/:id", api.ProductController{}.Category)
		defaultRouters.GET("/detail", api.ProductController{}.Detail)
		// 产品图片列表
		defaultRouters.GET("/product/getImgList", api.ProductController{}.GetImgList)
		// 购物车相关
		defaultRouters.GET("/cart/addCart", api.CartController{}.AddCart)
		defaultRouters.GET("/cart/decCart", api.CartController{}.DecCart)
		defaultRouters.GET("/cart/IncCart", api.CartController{}.IncCart)
		defaultRouters.GET("/changeOneCart", api.CartController{}.ChangeOneCart)
		defaultRouters.GET("/changeAllCart", api.CartController{}.ChangeAllCart)
		defaultRouters.DELETE("/delCart", api.CartController{}.DelCart)
		defaultRouters.GET("/cart", api.CartController{}.Get)
		// 商城用户模块
		defaultRouters.POST("/pass/login", api.PassController{}.Login)
		defaultRouters.GET("/pass/logout", api.PassController{}.Logout)
		defaultRouters.GET("/pass/captcha", api.PassController{}.Captcha)
		defaultRouters.GET("/pass/validateSmsCode", api.PassController{}.ValidateSmsCode)
		defaultRouters.GET("/pass/sendCode", api.PassController{}.SendCode)
		defaultRouters.GET("/pass/registerStep1", api.PassController{}.RegisterStep1)
		defaultRouters.GET("/pass/registerStep2", api.PassController{}.RegisterStep2)
		defaultRouters.GET("/pass/registerStep3", api.PassController{}.RegisterStep3)
		defaultRouters.POST("/pass/doRegister", api.PassController{}.DoRegister)
		// 结算
		defaultRouters.GET("/buy/checkout", InitUserAuthMiddleware, api.BuyController{}.Checkout) // 这里配置了局部中间件
		defaultRouters.POST("/buy/createOrder", InitUserAuthMiddleware, api.BuyController{}.Buy)
		defaultRouters.POST("/buy/pay", InitUserAuthMiddleware, api.BuyController{}.Pay)
		// 收货地址
		defaultRouters.POST("/address", InitUserAuthMiddleware, api.AddressController{}.AddAddress)
		defaultRouters.GET("/address/:id", InitUserAuthMiddleware, api.AddressController{}.GetOneAddress)
		defaultRouters.PUT("/address/:id/", InitUserAuthMiddleware, api.AddressController{}.EditAddress)
		defaultRouters.DELETE("/address/:id", InitUserAuthMiddleware, api.AddressController{}.DElAddress)
		defaultRouters.PUT("/defaultAddress/:id/", InitUserAuthMiddleware, api.AddressController{}.ChangeDefaultAddress)
		// 支付宝支付接口
		defaultRouters.GET("/v2/alipay", api.BuyController{}.AliPay)        // 这个是前端请求用的
		defaultRouters.POST("/v2/notify", api.BuyController{}.AlipayNotify) // 支付宝异步回调用的是POST请求
		defaultRouters.GET("/v2/return", api.BuyController{}.AlipayReturn)  // 支付宝同步回调用的是GET请求
		// 微信支付接口
		defaultRouters.GET("/wxPay", api.BuyController{}.WxPay)
		defaultRouters.POST("/wxPay/notify", api.BuyController{}.WxPayNotify)
		defaultRouters.GET("/orderPayStatus/:id", api.BuyController{}.OrderPayStatus)
		// 用户中心
		defaultRouters.GET("/user/index", api.UserController{}.Index)
		defaultRouters.GET("/user/orderList", api.UserController{}.OrderList)
		defaultRouters.GET("/user/orderInfo/:id", api.UserController{}.OrderInfo)
		defaultRouters.POST("/test", api.UserController{}.Test)
		defaultRouters.GET("/test2", api.UserController{}.T2)
		// elasticSearch
		defaultRouters.GET("/e1", tool.SearchController{}.Index)
		defaultRouters.GET("/e2", tool.SearchController{}.Add)
		defaultRouters.GET("/e3", tool.SearchController{}.Edit)
		defaultRouters.GET("/e4", tool.SearchController{}.Delete)
		defaultRouters.GET("/e5", tool.SearchController{}.GetOne)
		defaultRouters.GET("/e6", tool.SearchController{}.VagueSearch)
		defaultRouters.GET("/e7", tool.SearchController{}.PaginationSearch)
		defaultRouters.GET("/e8", tool.SearchController{}.FilterSearch)
		//微服务
		defaultRouters.GET("/go/goods", tool.GoodsController{}.Index)
	}
}
